<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
	<title>API: animation   Bezier.js  (YUI Library)</title>
	<link rel="stylesheet" type="text/css" href="assets/api.css">
</head>

<body id="yahoo-com">
<div id="doc3" class="yui-t2">

	<div id="hd">
        <h1>Yahoo! UI Library</h1>
        <h3>animation&nbsp; <span class="subtitle">2.2.2</span></h3>
        <p>
        <a href="./index.html">Yahoo! UI Library</a> 
            &gt; <a href="./module_animation.html">animation</a>
                
                 &gt; Bezier.js (source view) 
            </p>
	</div>

	<div id="bd">
		<div id="yui-main">
			<div class="yui-b">

                    <div id="srcout">
<div class="highlight" ><pre><span class="c">/**</span>
<span class="c"> * Used to calculate Bezier splines for any number of control points.</span>
<span class="c"> * @class Bezier</span>
<span class="c"> * @namespace YAHOO.util</span>
<span class="c"> *</span>
<span class="c"> */</span>
<span class="nx">YAHOO</span><span class="o">.</span><span class="nx">util</span><span class="o">.</span><span class="nx">Bezier</span> <span class="o">=</span> <span class="k">new</span> <span class="k">function</span><span class="o">()</span> <span class="o">{</span>
    <span class="c">/**</span>
<span class="c">     * Get the current position of the animated element based on t.</span>
<span class="c">     * Each point is an array of &quot;x&quot; and &quot;y&quot; values (0 = x, 1 = y)</span>
<span class="c">     * At least 2 points are required (start and end).</span>
<span class="c">     * First point is start. Last point is end.</span>
<span class="c">     * Additional control points are optional.     </span>
<span class="c">     * @method getPosition</span>
<span class="c">     * @param {Array} points An array containing Bezier points</span>
<span class="c">     * @param {Number} t A number between 0 and 1 which is the basis for determining current position</span>
<span class="c">     * @return {Array} An array containing int x and y member data</span>
<span class="c">     */</span>
    <span class="k">this</span><span class="o">.</span><span class="nx">getPosition</span> <span class="o">=</span> <span class="k">function</span><span class="o">(</span><span class="nx">points</span><span class="o">,</span> <span class="nx">t</span><span class="o">)</span> <span class="o">{</span>  
        <span class="k">var</span> <span class="nx">n</span> <span class="o">=</span> <span class="nx">points</span><span class="o">.</span><span class="nx">length</span><span class="o">;</span>
        <span class="k">var</span> <span class="nx">tmp</span> <span class="o">=</span> <span class="o">[];</span>

        <span class="k">for</span> <span class="o">(</span><span class="k">var</span> <span class="nx">i</span> <span class="o">=</span> <span class="m">0</span><span class="o">;</span> <span class="nx">i</span> <span class="o">&lt;</span> <span class="nx">n</span><span class="o">;</span> <span class="o">++</span><span class="nx">i</span><span class="o">){</span>
            <span class="nx">tmp</span><span class="o">[</span><span class="nx">i</span><span class="o">]</span> <span class="o">=</span> <span class="o">[</span><span class="nx">points</span><span class="o">[</span><span class="nx">i</span><span class="o">][</span><span class="m">0</span><span class="o">],</span> <span class="nx">points</span><span class="o">[</span><span class="nx">i</span><span class="o">][</span><span class="m">1</span><span class="o">]];</span> <span class="c">// save input</span>
<span class="c"></span>        <span class="o">}</span>
        
        <span class="k">for</span> <span class="o">(</span><span class="k">var</span> <span class="nx">j</span> <span class="o">=</span> <span class="m">1</span><span class="o">;</span> <span class="nx">j</span> <span class="o">&lt;</span> <span class="nx">n</span><span class="o">;</span> <span class="o">++</span><span class="nx">j</span><span class="o">)</span> <span class="o">{</span>
            <span class="k">for</span> <span class="o">(</span><span class="nx">i</span> <span class="o">=</span> <span class="m">0</span><span class="o">;</span> <span class="nx">i</span> <span class="o">&lt;</span> <span class="nx">n</span> <span class="o">-</span> <span class="nx">j</span><span class="o">;</span> <span class="o">++</span><span class="nx">i</span><span class="o">)</span> <span class="o">{</span>
                <span class="nx">tmp</span><span class="o">[</span><span class="nx">i</span><span class="o">][</span><span class="m">0</span><span class="o">]</span> <span class="o">=</span> <span class="o">(</span><span class="m">1</span> <span class="o">-</span> <span class="nx">t</span><span class="o">)</span> <span class="o">*</span> <span class="nx">tmp</span><span class="o">[</span><span class="nx">i</span><span class="o">][</span><span class="m">0</span><span class="o">]</span> <span class="o">+</span> <span class="nx">t</span> <span class="o">*</span> <span class="nx">tmp</span><span class="o">[</span><span class="nb">parseInt</span><span class="o">(</span><span class="nx">i</span> <span class="o">+</span> <span class="m">1</span><span class="o">,</span> <span class="m">10</span><span class="o">)][</span><span class="m">0</span><span class="o">];</span>
                <span class="nx">tmp</span><span class="o">[</span><span class="nx">i</span><span class="o">][</span><span class="m">1</span><span class="o">]</span> <span class="o">=</span> <span class="o">(</span><span class="m">1</span> <span class="o">-</span> <span class="nx">t</span><span class="o">)</span> <span class="o">*</span> <span class="nx">tmp</span><span class="o">[</span><span class="nx">i</span><span class="o">][</span><span class="m">1</span><span class="o">]</span> <span class="o">+</span> <span class="nx">t</span> <span class="o">*</span> <span class="nx">tmp</span><span class="o">[</span><span class="nb">parseInt</span><span class="o">(</span><span class="nx">i</span> <span class="o">+</span> <span class="m">1</span><span class="o">,</span> <span class="m">10</span><span class="o">)][</span><span class="m">1</span><span class="o">];</span> 
            <span class="o">}</span>
        <span class="o">}</span>
    
        <span class="k">return</span> <span class="o">[</span> <span class="nx">tmp</span><span class="o">[</span><span class="m">0</span><span class="o">][</span><span class="m">0</span><span class="o">],</span> <span class="nx">tmp</span><span class="o">[</span><span class="m">0</span><span class="o">][</span><span class="m">1</span><span class="o">]</span> <span class="o">];</span> 
    
    <span class="o">};</span>
<span class="o">};</span>
</pre></div>
                    </div>
			</div>
		</div>
		<div class="yui-b">
            <div class="nav">

                    <div class="module">
                        <h4>Modules</h4>
                        <ul class="content">

                                <li class="selected"><a href="module_animation.html">animation</a></li>

                                <li class=""><a href="module_autocomplete.html">autocomplete</a></li>

                                <li class=""><a href="module_button.html">button</a></li>

                                <li class=""><a href="module_calendar.html">calendar</a></li>

                                <li class=""><a href="module_connection.html">connection</a></li>

                                <li class=""><a href="module_container.html">container</a></li>

                                <li class=""><a href="module_datasource.html">datasource</a></li>

                                <li class=""><a href="module_datatable.html">datatable</a></li>

                                <li class=""><a href="module_dom.html">dom</a></li>

                                <li class=""><a href="module_dragdrop.html">dragdrop</a></li>

                                <li class=""><a href="module_element.html">element</a></li>

                                <li class=""><a href="module_event.html">event</a></li>

                                <li class=""><a href="module_history.html">history</a></li>

                                <li class=""><a href="module_logger.html">logger</a></li>

                                <li class=""><a href="module_menu.html">menu</a></li>

                                <li class=""><a href="module_slider.html">slider</a></li>

                                <li class=""><a href="module_tabview.html">tabview</a></li>

                                <li class=""><a href="module_treeview.html">treeview</a></li>

                                <li class=""><a href="module_yahoo.html">yahoo</a></li>
                        </ul>
                    </div>

                    <div class="module">
                        <h4>Classes</h4>
                        <ul class="content">
                                <li class=""><a href="YAHOO.util.Anim.html">YAHOO.util.Anim</a></li>
                                <li class=""><a href="YAHOO.util.AnimMgr.html">YAHOO.util.AnimMgr</a></li>
                                <li class=""><a href="YAHOO.util.Bezier.html">YAHOO.util.Bezier</a></li>
                                <li class=""><a href="YAHOO.util.ColorAnim.html">YAHOO.util.ColorAnim</a></li>
                                <li class=""><a href="YAHOO.util.Easing.html">YAHOO.util.Easing</a></li>
                                <li class=""><a href="YAHOO.util.Motion.html">YAHOO.util.Motion</a></li>
                                <li class=""><a href="YAHOO.util.Scroll.html">YAHOO.util.Scroll</a></li>
                        </ul>
                    </div>

                    <div class="module">
                        <h4>Files</h4>
                        <ul class="content">        
                                <li class=""><a href="Anim.js.html">Anim.js</a></li>
                                <li class=""><a href="AnimMgr.js.html">AnimMgr.js</a></li>
                                <li class="selected"><a href="Bezier.js.html">Bezier.js</a></li>
                                <li class=""><a href="ColorAnim.js.html">ColorAnim.js</a></li>
                                <li class=""><a href="Easing.js.html">Easing.js</a></li>
                                <li class=""><a href="Motion.js.html">Motion.js</a></li>
                                <li class=""><a href="Scroll.js.html">Scroll.js</a></li>
                        </ul>
                    </div>





            </div>
		</div>
	</div>
	<div id="ft">
        <hr />
        Copyright &copy; 2007 Yahoo! Inc. All rights reserved.
	</div>
</div>
</body>
</html>
